﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

namespace DataAccess
{
    public class SysConfigsData
    {
        public string GetParaByName(string name)
        {
            DataTable dt = new DataTable();
            Database database = DatabaseFactory.CreateDatabase();
            string sqlCommand = "SysConfigsGetByName";
            DbCommand dbCommand = database.GetStoredProcCommand(sqlCommand);
            database.AddOutParameter(dbCommand, "@AffectRows", DbType.Int32, 10);
            database.AddInParameter(dbCommand, "@ParaName", DbType.String, name);           
            dt=database.ExecuteDataSet(dbCommand).Tables[0];
            return dt.Rows[0]["ParaValue"].ToString();            
        }
        public bool UpdateParaByName(string name, string value)
        {
            DataTable dt = new DataTable();
            Database database = DatabaseFactory.CreateDatabase();
            string sqlCommand = "SysConfigsUpdateByName";
            DbCommand dbCommand = database.GetStoredProcCommand(sqlCommand);
            database.AddOutParameter(dbCommand, "@AffectRows", DbType.Int32, 10);
            database.AddInParameter(dbCommand, "@ParaName", DbType.String, name);
            database.AddInParameter(dbCommand, "@ParaValue", DbType.String, value);
            database.ExecuteNonQuery(dbCommand);
            int returnValue = int.Parse(database.GetParameterValue(dbCommand, "@AffectRows").ToString());
            return returnValue > 0 ? true : false;
        }
    }
}
